﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace INF7GEN
{
    [Serializable()]
    public class Extensions : ISerializable
    {
        private static int numExtensionObjects;//non accessible to outside methods

        private string name = "Extensions Object" + numExtensionObjects;
        private bool ADVBOOK = false;//true if in adventure book mode
        private List<ADVBookPage> pages = new List<ADVBookPage>();//used only in adventure book games, equivalent to a level
        private List<ADVBookFlag> flags = new List<ADVBookFlag>();//used only in adventure book games, bool like values used in game



        public Extensions ()
        {
            ++numExtensionObjects;
        }


        //--------------------------------------------------------------------
        //Serialization-------------------------------------------------------
        public Extensions(SerializationInfo info, StreamingContext ctxt)
        {
            this.ADVBOOK = (bool)info.GetValue("EXTENSIONSADVBOOK", typeof(bool));
            this.name = (string)info.GetValue("EXTENSIONSname", typeof(string));
            this.pages = (List<ADVBookPage>)info.GetValue("EXTENSIONSPages", typeof(List<ADVBookPage>));
            this.flags = (List<ADVBookFlag>)info.GetValue("EXTENSIONSFlags", typeof(List<ADVBookFlag>));
            ++numExtensionObjects;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("EXTENSIONSADVBOOK", this.ADVBOOK);
            info.AddValue("EXTENSIONSname", this.name);
            info.AddValue("EXTENSIONSPages", this.pages);
            info.AddValue("EXTENSIONSFlags", this.flags);
        }
        //-------------------------------------------------------------------






        public override string ToString()
        {
            return this.name;
        }








        /// <summary>
        /// accessor methods
        /// </summary>
        public bool ADVENTUREBOOK
        {
            get { return ADVBOOK; }
            set { ADVBOOK = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }


        /// <summary>
        /// list of pages
        /// </summary>
        public List<ADVBookPage> ListOfPages
        {
            get { return pages; }
            set { pages = value; }
        }

        /// <summary>
        /// list of flags
        /// </summary>
        public List<ADVBookFlag> ListOfFlags
        {
            get { return flags; }
            set { flags = value; }
        }

        /// <summary>
        /// get indexed page in list
        /// </summary>
        public ADVBookPage getPage(int pageIndex)
        {
            if (pages.Count - 1 < pageIndex)
            {
                return null;
            }

            return pages.ElementAt(pageIndex);
        }

        /// <summary>
        /// get indexed flag in list
        /// </summary>
        public ADVBookFlag getFlag(int flagIndex)
        {
            if (flags.Count - 1 < flagIndex)
            {
                return null;
            }

            return flags.ElementAt(flagIndex);
        }



    }
}
